package com.lsh.test2;

import com.alibaba.druid.pool.DruidDataSource;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.Connection;
import java.util.ResourceBundle;

public class MyTest {
    @Test
    public void druidTest() throws Exception {
        ResourceBundle jdbc = ResourceBundle.getBundle("jdbc");

        //使用无参构造方法创建数据源对象
        DruidDataSource druid=new DruidDataSource();
        //通过setter方法对连接属性进行赋值
        druid.setDriverClassName(jdbc.getString("jdbc.driver"));
        druid.setUrl(jdbc.getString("jdbc.url"));
        druid.setUsername(jdbc.getString("jdbc.username"));
        druid.setPassword(jdbc.getString("jdbc.password"));
        //获取连接
        Connection connection = druid.getConnection();
        System.out.println(connection);
        //归还连接 关闭连接池
        connection.close();
        druid.close();
    }

    @Test
    public void druid() throws Exception {
        //使用无参构造方法创建数据源对象
        DruidDataSource druid=new DruidDataSource();
        //通过setter方法对连接属性进行赋值
        druid.setDriverClassName("com.mysql.jdbc.Driver");
        druid.setUrl("jdbc:mysql:///test");
        druid.setUsername("root");
        druid.setPassword("123456");
        //获取连接
        Connection connection = druid.getConnection();
        System.out.println(connection);
        //归还连接 关闭连接池
        connection.close();
        druid.close();
    }
    @Test
    public void u1(){
        ClassPathXmlApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");
        Object u1 = applicationContext.getBean("u1");
        System.out.println(u1);
        applicationContext.close();
    }
}
